package org.jeecg.modules.controller.human;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.entity.DbStation;
import org.jeecg.modules.service.IDbStationService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

import static kotlin.reflect.jvm.internal.impl.builtins.StandardNames.FqNames.list;

/**
 * @Description: db_station
 * @Author: jeecg-boot
 * @Date:   2024-07-08
 * @Version: V1.0
 */
//@Api(tags="db_station")
@RestController
@RequestMapping("/dbStation")
@Slf4j
public class DbStationController extends JeecgController<DbStation, IDbStationService> {
	@Autowired
	private IDbStationService dbStationService;

	/**
	 * 部门岗位联级差询
	 * @return
	 */
//	@ApiOperation(value = "部门岗位联级差询", notes = "部门岗位联级差询")
	@GetMapping("/listDepartAndStation")
	public Result<List<DbStation>> departStationList() {
		List<DbStation> list = dbStationService.listDepartAndStation();
		return Result.OK(list);
	}
	/**
	* 获取部门
	* @return
	*/
//	@ApiOperation(value = "获取部门", notes = "获取部门")
	@GetMapping("/getDepartment")
	public Result<List<DbStation>> getDepartment() {
		QueryWrapper<DbStation> queryWrapper = new QueryWrapper<>();
		queryWrapper.isNull("parent_id");
		List<DbStation> list = dbStationService.list(queryWrapper);
		return Result.OK(list);
	}
	/**
	 * 根据部门获取岗位
	 * @return
	 */
//	@ApiOperation(value = "根据部门获取岗位", notes = "根据部门获取岗位")
	@GetMapping("/getStation")
	public Result<List<DbStation>> getStation(@RequestParam(name="id",required=true) String id) {
		QueryWrapper<DbStation> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("parent_id", id);
		List<DbStation> list = dbStationService.list(queryWrapper);
		return Result.OK(list);
	}
	/**
	 * 根据岗位获取级别
	 * @return
	 */
//	@ApiOperation(value = "根据岗位获取级别", notes = "根据岗位获取级别")
	@GetMapping("/getLev")
	public Result<List<DbStation>> getLev(@RequestParam(name="id",required=true) String id) {
		QueryWrapper<DbStation> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("parent_id",id);
		List<DbStation> list = dbStationService.list(queryWrapper);
		return Result.OK(list);
	}


	/**
	 * 岗位分页列表查询
	 *
	 * @param dbStation
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "db_station-分页列表查询")
//	@ApiOperation(value="db_station-分页列表查询", notes="db_station-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<DbStation>> queryPageList(DbStation dbStation,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<DbStation> queryWrapper = QueryGenerator.initQueryWrapper(dbStation, req.getParameterMap());
		queryWrapper.isNull("lev").isNotNull("station");
		Page<DbStation> page = new Page<DbStation>(pageNo, pageSize);
		IPage<DbStation> pageList = dbStationService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	/**
	 * 级别分页列表查询
	 *
	 * @param dbStation
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "db_station-级别分页列表查询")
//	@ApiOperation(value="db_station-级别分页列表查询", notes="db_station-级别分页列表查询")
	@GetMapping(value = "/listLev")
	public Result<IPage<DbStation>> queryPageListLev(DbStation dbStation,
												  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
												  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
												  HttpServletRequest req) {
		QueryWrapper<DbStation> queryWrapper = QueryGenerator.initQueryWrapper(dbStation, req.getParameterMap());
		queryWrapper.isNotNull("lev");
		Page<DbStation> page = new Page<DbStation>(pageNo, pageSize);
		IPage<DbStation> pageList = dbStationService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param dbStation
	 * @return
	 */
	@AutoLog(value = "db_station-添加")
//	@ApiOperation(value="db_station-添加", notes="db_station-添加")
	//@RequiresPermissions("org.jeecg.modules:db_station:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody DbStation dbStation) {
		dbStationService.save(dbStation);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param dbStation
	 * @return
	 */
	@AutoLog(value = "db_station-编辑")
//	@ApiOperation(value="db_station-编辑", notes="db_station-编辑")
	//@RequiresPermissions("org.jeecg.modules:db_station:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody DbStation dbStation) {
		dbStationService.updateById(dbStation);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "db_station-通过id删除")
//	@ApiOperation(value="db_station-通过id删除", notes="db_station-通过id删除")
	//@RequiresPermissions("org.jeecg.modules:db_station:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		dbStationService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "db_station-批量删除")
//	@ApiOperation(value="db_station-批量删除", notes="db_station-批量删除")
	//@RequiresPermissions("org.jeecg.modules:db_station:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.dbStationService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "db_station-通过id查询")
//	@ApiOperation(value="db_station-通过id查询", notes="db_station-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<DbStation> queryById(@RequestParam(name="id",required=true) String id) {
		DbStation dbStation = dbStationService.getById(id);
		if(dbStation==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(dbStation);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param dbStation
    */
    //@RequiresPermissions("org.jeecg.modules:db_station:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, DbStation dbStation) {
        return super.exportXls(request, dbStation, DbStation.class, "db_station");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("db_station:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, DbStation.class);
    }

}
